home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 4
/
Apprentice-Release4.iso
/
Languages
/
Yerk 3.6.7
/
yerk 367
/
System source
/
Args
< prev
next >
Wrap
Text File
|
1986-10-04
|
7KB
|
213 lines
\ args - non-class support for named input parms, local variables
\ 6/28/85 cbd Dispose> named parms works correctly
\ 7/03/85 cbd Clear parmList in Pfind if interpreting
\ 9/24/85 cbd Hooks for floating point named args
\ 9/16/86 cdn Fixed dispose> to work for MM blocks as well as heap objects
0 value inParms \ # named input parameters
0 value locFlg \ true=looking for local var tokens
0 value fltMask \ bit on for each float parm
6 constant maxParms
\ stub for floating point pick words - patched by float package
: fstub cr ?error 167 ; \ Floating Point not installed
\ tables of pick and store cfas
6 'cfas mp5 mp4 mp3 mp2 mp1 mp0
variable mpicks , , , , ,
6 'cfas ms5 ms4 ms3 ms2 ms1 ms0
variable mputs , , , , ,
6 'cfas fstub fstub fstub fstub fstub fstub \ cbd 9/85 float support
variable fpicks , , , , ,
\ ( ind addr -- elem ) fetch an element from mpicks, mputs
: @mp swap 4* + @ ;
\ define an mcfa structure for 8-byte lists. This will hold
\ the symbol table of input parm names during compilation of a word.
3 Codefields 2 Prefix init8 1 prefix ++8
\ 2cfa clears the list
' init8 Do.. 0 swap w! ..End
\ ( dElem -- ) 1cfa adds double element to list
' ++8 Do.. >R R w@ R 2+ w@ >= ?error 110
R w@ 1 R w+! \ get current ind, incr by 1
8 * 4+ R> + 2! ..End \ calc addr of element and store
\ ( dElem -- ind t OR f ) Search for element in list
Do.. Pushm 0 rot rot copyM W@ 0 \ For current size, DO
DO I 8 * 4+ Copym + 2@ 2over D= \ compare to this element
IF 2drop drop I 1 1 1 Leave THEN
LOOP 2drop Dropm ..End \ could have used named parms here!!
\ define the builder for 8-byte lists
: List8 Build 0 w, dup w, \ current size, max size
8 * reserve ..End
maxParms list8 ParmList
\ Pad for WORD format string Len|xxxxxxxxxx
\ ( addr n -- ) Pad a string with blanks to n chars
: PadBL
swap >R dup R c@ - dup 0>
IF R c@ R + 1+ swap blanks
ELSE drop THEN R> c! ; \ Update length byte
\ ( addr -- ) Copy the string at addr to Pad+1
: ToPad dup c@ Pad 1+ swap 1+ cmove ;
\ ( -- char ) Get the first chart of the word at Here
: firstChr Here 1+ c@ ;
Forward LocalFloat
\ Begin a stack descriptor, reading parameters until }
\ format: : wordName { in1 in2 in3 \ loc1 loc2 loc3 -- out1 out2}
\ ( -- )
: { ?Comp init8 ParmList 0 put fltMask
0 put inparms 0 put locFlg \ ADDPARMS
BEGIN BL word \ Add parms or vars to parmlist
firstChr ascii - <> \ look for --
WHILE firstChr ascii \ =
IF true put locFlg
ELSE firstChr ascii } =
?error 111
locFlg 0= \ ADDPNAME - Add parm name at Here to list
IF inParms 1+ put inparms THEN \ bump # input parms
firstChr ascii % = \ float parm?
IF 1 ' Parmlist 8+ w@ << fltMask or put fltMask THEN
Here ToPad Pad 1+ 8 PadBL
Pad 2+ 2@ ++8 ParmList
THEN
REPEAT
' Parmlist 8+ w@ -dup \ get current size
IF inParms - 4 << inParms or c, fltMask c,
CState 0= IF 'code colP here 6 - ! THEN
THEN
BEGIN BL word firstChr 0= ?error 112
firstChr ascii } = \ eat characters until }
UNTIL
fltMask inparms >> IF Compile LocalFloat THEN
; Immediate
\ ( addr -- ind t OR f ) Look up string in ParmList
: (PFind) ToPad Pad 1+ 8 PadBl
Pad 2+ 2@ ParmList dup \ look for this element
IF pad 2+ c@ ascii % =
IF swap 6 + swap THEN
THEN ; \ cbd 9/85 float arg
\ -Find will call Pfind to attempt to find a name first
\ ( -- f OR mpickPfa 0 t )
: Pfind
State 0=
IF init8 parmList 0 \ cbd 7/03/85
ELSE Here (Pfind)
IF dup 6 <
IF MPicks @mp 4+ 0 1
ELSE 6 - fpicks @mp 4+ 0 1
THEN
ELSE 0 THEN
THEN ;
\ return the type of a token for prefix. An index of 0-5
\ indicates a named parm, and a Forth word returns its cfa.
\ ( -- cfa type )
: prfToken @word (pfind)
IF dup
ELSE here latest (find) 0= ?error 113
drop cfa dup @
THEN ;
'code vmodel constant vectCode
'code keyvec constant svcode
'code in constant valCode
0 value modCode
0 value fvalCode \ float package must patch
'c fstub value farg! \ float cbd 9/85
'c fstub value farg++ \ float cbd 9/85
'c fstub value fKill
\ compile a cfa if in compile state, else exec it.
: ,exec state IF , ELSE execute THEN ;
\ the following prefix compilers detect whether their subject is
\ a Value, Vect or named parm, which allows them to operate
\ on all types of variables.
\ ( val -- ) Store stack value in named parm location
: -> prfToken
CASE
0 5 RANGEOF ?comp Mputs @mp , ENDOF
6 11 RANGEOF ?comp farg! , 6 - 4* 8+ w, ENDOF \ float arg
vectCode OF 8+ ,exec ENDOF \ compile 2cfa for store
svCode OF 8+ ,exec ENDOF
valCode OF 8+ ,exec ENDOF
fvalCode OF 8+ ,exec ENDOF \ cbd 9/85
?error 114
ENDCASE ; Immediate
\ the following build a named parm ref by compiling the cfa of the
\ runtime word followed by a word containing the offset of the
\ named parm from the top of the mStack
\ ( val -- ) increment a named parm
: ++> prfToken
CASE
0 5 RANGEOF Compile (++>) 4* 8+ w, ENDOF
6 11 RANGEOF ?comp farg++ , 6 - 4* 8+ w, ENDOF \ float arg
valCode OF 4+ ,exec ENDOF
fvalCode OF 4+ ,exec ENDOF \ cbd 9/85 float arg
?error 114
ENDCASE ; Immediate
\ ( -- ) execute a procedural argument or variable
: Exec> prfToken
CASE
0 5 RANGEOF Compile (ex>) 4* 8+ w, ENDOF
vectCode OF ,exec ENDOF \ compile 0cfa for execute
svCode OF ,exec ENDOF
valCode OF ,exec 'c execute ,exec ENDOF
?error 114
ENDCASE ; Immediate
Forward ?isObj \ defined in Class
\ ( addr -- ) release block and 0 its vector
: Dispose dup @ -dup
IF ?isObj IF cfa THEN \ is a heap object
killPtr
THEN 0 swap ! ;
\ dispose> operation for value & method stack referenced data
: (disp) R @ R> 4+ >R dispose ;
: (mdisp) R w@ R> 2+ >R 2+ 4* mp@ + dispose ;
: Dispose> prfToken
CASE
0 5 RANGEOF ?comp Compile (mdisp) w, ENDOF
valCode OF Compile (disp) dup @ 2- W@ + , ENDOF
modCode OF 8+ ,exec ENDOF \ module
?error 114
ENDCASE ; Immediate
\ redefine exit & semicolon to support floating point named args. IF
\ the word being compiled has float args, the second byte after the cfa
\ will be non-0, containing the arg type bitmask. Dispose of args before exit.
: exit latest pfa cfa @ colCode =
IF Compile ;s
ELSE latest pfa 1+ c@ dup
IF fKill , w, ELSE drop THEN
Compile (semip)
THEN ; Immediate
: ; ?csp cState ?error 163 \ Use ;M to terminate methods
latest c@ $ df and latest c! \ be sure any smudge is undone
[Compile] exit [Compile] <[ exit <[ Immediate
\ ' Pfind Cfa -> Ufind
<" Class